package com.mercenary.wein.screenControl.ui.batch;

import com.mercenary.wein.screenControl.command.CommandTool;
import com.mercenary.wein.screenControl.ui.util.Constants;

import javax.swing.*;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;

public class SendStateInFriendCircle extends JDialog implements ActionListener, ItemListener {
    GroupCheckBoxPanel LocationJ1 = new GroupCheckBoxPanel();//面板1
    JPanel LocationJ2 = new JPanel();//面板2
    JPanel LocationJ3 = new JPanel();//面板2上的主操作面板
    JPanel LocationJ6 = new JPanel();
    static JFrame locationjf = new JFrame();
    final List<File> choosedFile = new ArrayList<File>();

    public SendStateInFriendCircle() {
        super(locationjf, "发朋友圈");
        setBounds(200, 100, 700, 550);
        setLayout(new BorderLayout());
        setVisible(true);
        add(LocationJ1, BorderLayout.WEST);
        add(LocationJ2, BorderLayout.EAST);
        LocationJ1.setPreferredSize(new Dimension(180, 550));//设置大小
        LocationJ1.setBackground(Color.WHITE);
        LocationJ2.setPreferredSize(new Dimension(500, 550));
        LocationJ2.setBackground(Color.WHITE);

        Border titleBorder1 = BorderFactory.createTitledBorder("请选择在线设备");// 设置面板边框，实现分组框的效果       .设置面板边框颜色
        LocationJ1.setBorder(titleBorder1);

        //J2中的组件
        LocationJ2.setLayout(new BorderLayout());
        LocationJ2.add(LocationJ3, BorderLayout.SOUTH);
        LocationJ3.setPreferredSize(new Dimension(500, 490));
        LocationJ3.setBackground(Color.pink);
        SelectedNumLabel j1 = new SelectedNumLabel();
        LocationJ1.registerObserver(j1);
        LocationJ2.add(j1, BorderLayout.NORTH);
        JLabel j2 = new JLabel("请输入您的文案信息");
        final JTextArea textArea = new JTextArea(4, 4);
        textArea.setPreferredSize(new Dimension(200, 100));
        textArea.setTabSize(4);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        //textArea.setMaximumSize(100);
        JButton sendImage = new JButton("发送图片");
        JButton sendVideo = new JButton("发送视频");
        JButton excute = new JButton("立即发布");
        LocationJ3.add(j2);
        LocationJ3.add(textArea);
        LocationJ3.add(sendImage);
        LocationJ3.add(sendVideo);
        LocationJ3.add(excute);
        LocationJ2.validate();

        sendImage.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser fileChooser = new JFileChooser(Constants.RepertoryPath);// 以c:\\winnt为打开文件为对话框的默认路径
                int result = fileChooser.showOpenDialog(locationjf);
                // /如果选择确定按钮的话，那么则可以打开现有的文件
                if (result == JFileChooser.APPROVE_OPTION) {
                    File file = fileChooser.getSelectedFile();
                    choosedFile.add(file);
                }
                // /否则如果单击取消的话，那么就会在标签中显示"你没有选取文件"
                else if (result == fileChooser.CANCEL_OPTION) {
                }
            }
        });

        excute.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                CommandTool.publishPic(LocationJ1.getSelectedDevices(),choosedFile,textArea.getText());
                choosedFile.removeAll(choosedFile);
            }
        });

    }


    public static void main(String[] arge) {
        new SendStateInFriendCircle();
    }

    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

    }

    public void itemStateChanged(ItemEvent e) {
        // TODO Auto-generated method stub

    }
}

